package com.agrimall.util;

import java.security.MessageDigest;

/**
 * MD5工具类
 */
public class MD5Util {
    
    /**
     * MD5加密
     */
    public static String md5(String str) {
        try {
            MessageDigest md = MessageDigest.getInstance("MD5");
            byte[] bytes = md.digest(str.getBytes("UTF-8"));
            StringBuilder sb = new StringBuilder();
            for (byte b : bytes) {
                sb.append(String.format("%02x", b));
            }
            return sb.toString();
        } catch (Exception e) {
            throw new RuntimeException("MD5加密失败", e);
        }
    }
    
    /**
     * 测试方法：生成密码的MD5值
     */
    public static void main(String[] args) {
        System.out.println("admin123: " + md5("123456"));
        System.out.println("user123: " + md5("user123"));
        System.out.println("merchant123: " + md5("merchant123"));
    }
}

















